package com.grsu.TransportSystem.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.grsu.TransportSystem.dao.IProposalDAO;
import com.grsu.TransportSystem.domain.Person;
import com.grsu.TransportSystem.domain.Proposal;

@Service
public class ProposalService {
	
	@Autowired
	private IProposalDAO proposalDao;
	
	@Transactional
	public void createProposal(Proposal object)
	{
			proposalDao.create(object);
	}
	
	@Transactional
	public List<Proposal> getProposal(Proposal example)
	{
		return proposalDao.read(example);
	}
	
	@Transactional
	public void deleteProposal(Proposal object)
	{
		proposalDao.delete(object);
	}
	
	@Transactional
	public void updateProposal(Proposal object)
	{
		proposalDao.update(object);
	}
	
	@Transactional
	public void updateProposalDriver(Proposal object)
	{
		proposalDao.updateDriver(object);
	}
	
	@Transactional
	public void updateProposalState(Proposal object)
	{
		proposalDao.updateState(object);
	}
	
	
	@Transactional
	public Proposal getProposalById(String id)
	{
		Proposal example = new Proposal();
		example.setId(id);
		List<Proposal> list = proposalDao.read(example);
		if(list != null && list.size()>0)
			return list.get(0);
		return null;
	}
	
	@Transactional
	public List<Proposal> getProposalByDriver(Person driver)
	{
		return proposalDao.readByDriver(driver);
	}
}
